﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace com.dbo
{
    public class Level
    {
        com.net.Level p = new com.net.Level();

        public Level() { }
        public Level(com.net.Level data)
        {
            p = data;
        }
        public com.net.Level Data
        {
            get { return p; }
            set { p = value; }
        }
        public void Add()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("addlevel");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("levelid", p.LevelID);
            cmd.Parameters.AddWithValue("level", p.LevelName);
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
        public void Update()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("updatelevel");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("levelid", p.LevelID);
            cmd.Parameters.AddWithValue("level", p.LevelName);
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
        public void Delete()
        {
            SqlCommand cmd = com.dbo.DB.getCmdSp("dellevel");
            cmd.Connection.Open();
            cmd.Parameters.AddWithValue("levelid", p.LevelID);
            
            int i = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return i == 1;
        }
        public bool  Fetch()
        {
            DataTable dt = com.dbo.DB.getTable("select * from adc_level where levelid=" + p.LevelID);

            if (dt.Rows.Count == 0)
                return false;

            p.LevelName = dt.Rows[0][1].ToString();
            return true;
        }

    }
}